// ==UserScript==
// @name         beijingToken
// @namespace    https://gitee.com/blb19900404/tampermonkey/tree/master
// @version      1.0.3
// @description  获取京办的token
// @author       zf
// @match        http://101.200.161.122:30002/*
// @match        https://sp.scjgj.beijing.gov.cn/occ/dt_cs/*
// @icon         
// @updateURL    https://gitee.com/blb19900404/tampermonkey/raw/master/script/beijingToken.js
// @downloadURL  https://gitee.com/blb19900404/tampermonkey/raw/master/script/beijingToken.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let customAlert = (message) => {
        // 使用原生JavaScript创建一个div作为模拟alert框
        var divaa = document.createElement('div');
        divaa.innerHTML = "<div style='margin-top: 10%; margin-left: 35%;;width: 30%;padding: 15px;border-radius: 14px;background-color: white;box-shadow: rgb(153, 153, 153) 0px 7px 20px;z-index: 100;word-break: break-all;'><span style='user-select: all;'>" + message + "</span><div style='margin-top:10px;display: flex;justify-content: flex-end'></div></div>";
        divaa.style.position = 'fixed';
        divaa.style.top = '0%';
        divaa.style.left = '0%';
        divaa.style.width = '100%';
        divaa.style.height = '100%';
        divaa.style.background = 'rgb(0,0,0,0.3)';
        divaa.style.zIndex = '99';

        // // 添加关闭按钮
        var closeBtn = document.createElement('div');
        closeBtn.innerHTML = "<span style='cursor:pointer;padding:6px 14px; background-color: #3f51b5; color: #fff; border-radius: 20px;'> 确认 </span>"
        closeBtn.style.marginTop = '20px';
        closeBtn.style.display = 'flex';
        closeBtn.style.justifyContent = 'flex-end';
        //触发时关闭页面滚动
        document.body.style.overflow = 'hidden'
        closeBtn.querySelector('span').onclick = function () {
            divaa.parentNode.removeChild(divaa);
            //关闭时页面滚动
            document.body.style.overflow = 'visible'
        }
        divaa.firstChild.appendChild(closeBtn);
        // 将div添加到body中
        document.body.appendChild(divaa);
    }

    var open = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
        this.addEventListener('readystatechange', function() {
            if (this.readyState == 4 && this.status == 200) {
                // var oldResponse = this.responseText;
                // 修改响应数据
                if(url.includes('loginByJB')){
                    const res = JSON.parse(this.responseText);
                    const token= res.data.access_token
                    customAlert(token)
                }
            }
        }, false);
        open.apply(this, arguments);
    };
})();